﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class UserInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            init_org();
            init_User_Info();
        }
    }
    protected void Btn_Save_Click(object sender, EventArgs e)
    {
        int ret = 0;

        if (HF_Nav.Value.ToString() == "1")
        {

            if (HF_Type.Value.ToString() == "P")
            {
                UserPersonService.UserPersonService oService2 = new UserPersonService.UserPersonService();

                ret = oService2.AddUpdateUserPerson(Convert.ToInt32(Session["UserID"].ToString()), Lbl_No.Text.ToString(), Txb_NickName.Text.ToString(),
                        Txb_FullName.Text.ToString(), Txb_KeyWord1.Text.ToString(), Txb_KeyWord2.Text.ToString(),
                        Txb_KeyWord3.Text.ToString(), Txb_PID.Text.ToString(),
                        Txb_Address.Text.ToString(), Txb_Demo.Text.ToString(), Txb_Phone.Text.ToString(), Txb_FAX.Text.ToString(),
                        Session["LoginName"].ToString(), Txb_Mobile.Text.ToString(), Txb_QQ.Text.ToString(), Txb_MSN.Text.ToString(),
                        Txb_Blog.Text.ToString(), Txb_Weibo.Text.ToString(), Txb_WebSite.Text.ToString());

                if (ret <= 0)
                {
                    this.RegisterStartupScript("Msg", "<script>alert('修改失败！')</script>");
                    return;
                }


            }
            else if (HF_Type.Value.ToString() == "S")
            {

                UserShopService.UserShopService oService2 = new UserShopService.UserShopService();

                ret = oService2.AddUpdateUserShop(Convert.ToInt32(Session["UserID"].ToString()), Lbl_No.Text.ToString(), Txb_NickName.Text.ToString(),
                        Txb_FullName.Text.ToString(), Txb_KeyWord1.Text.ToString(), Txb_KeyWord2.Text.ToString(),
                        Txb_KeyWord3.Text.ToString(),
                        Txb_Address.Text.ToString(), Txb_Demo.Text.ToString(), Txb_Phone.Text.ToString(), Txb_FAX.Text.ToString(),
                        Session["LoginName"].ToString(), Txb_Mobile.Text.ToString(), Txb_ShopBoss.Text.ToString(), Txb_QQ.Text.ToString(), Txb_MSN.Text.ToString(),
                        Txb_Blog.Text.ToString(), Txb_Weibo.Text.ToString(), Txb_WebSite.Text.ToString());

                if (ret <= 0)
                {
                    this.RegisterStartupScript("Msg", "<script>alert('修改失败！')</script>");
                    return;
                }

            }
            else if (HF_Type.Value.ToString() == "C")
            {
                UserCompanyService.UserCompanyService oService2 = new UserCompanyService.UserCompanyService();

                ret = oService2.AddUpdateUserCompany(Convert.ToInt32(Session["UserID"].ToString()), Lbl_No.Text.ToString(), Txb_NickName.Text.ToString(),
                        Txb_FullName.Text.ToString(), Txb_KeyWord1.Text.ToString(), Txb_KeyWord2.Text.ToString(), Txb_KeyWord3.Text.ToString(),
                Txb_Address.Text.ToString(), Txb_Demo.Text.ToString(), Txb_Phone.Text.ToString(), Txb_FAX.Text.ToString(),
                    Session["LoginName"].ToString(), Txb_Mobile.Text.ToString(), Txb_QQ.Text.ToString(), Txb_MSN.Text.ToString(),
                        Txb_Blog.Text.ToString(), Txb_Weibo.Text.ToString(), Txb_WebSite.Text.ToString());

                if (ret <= 0)
                {

                    this.RegisterStartupScript("Msg", "<script>alert('修改失败！')</script>");
                    return;
                }
            }
            else if (HF_Type.Value.ToString() == "O")
            {

                UserOrganizationService.UserOrganizationService oService2 = new UserOrganizationService.UserOrganizationService();

                ret = oService2.AddUpdateUserOrganization(Convert.ToInt32(Session["UserID"].ToString()), Lbl_No.Text.ToString(), Txb_NickName.Text.ToString(),
                        Txb_FullName.Text.ToString(), Txb_KeyWord1.Text.ToString(), Txb_KeyWord2.Text.ToString(), Txb_KeyWord3.Text.ToString(),
                        Txb_Address.Text.ToString(), Txb_Demo.Text.ToString(), Txb_Phone.Text.ToString(), Txb_FAX.Text.ToString(),
                        Session["LoginName"].ToString(), Txb_Mobile.Text.ToString(), Txb_QQ.Text.ToString(), Txb_MSN.Text.ToString(),
                        Txb_Blog.Text.ToString(), Txb_Weibo.Text.ToString(), Txb_WebSite.Text.ToString());

                if (ret <= 0)
                {

                    this.RegisterStartupScript("Msg", "<script>alert('修改失败！')</script>");
                    return;
                }
            }

            this.RegisterStartupScript("Msg", "<script>alert('修改成功！')</script>");

            this.RegisterStartupScript("Msg", "<script>blendon('tabcontent2'); blendoff('tabcontent1');blendoff('tabcontent3');swichtabs('2');</script>");
            return;
        }
        else if (HF_Nav.Value.ToString() == "2")
        {
            if (Txb_OldPwd.Text.ToString() != Txb_OldPwdOk.Text.ToString())
            {
                this.RegisterStartupScript("Msg", "<script>alert('当前密码错误！')</script>");
                return;
            }

            UserMemberService.UserMemberService oService = new UserMemberService.UserMemberService();
            ret= oService.ChangePassword(Convert.ToInt32(Session["UserID"].ToString()), Txb_NewPwd.Text.ToString());

            if (ret > 0)
            {
                this.RegisterStartupScript("Msg", "<script>alert('修改成功！')</script>");
            }
            else
            {
                this.RegisterStartupScript("Msg", "<script>alert('修改失败！')</script>");
            }

            this.RegisterStartupScript("Msg", "<script>blendon('tabcontent3'); blendoff('tabcontent1');blendoff('tabcontent2');swichtabs('3');</script>");
            return;
        }
    }

    public void init_User_Info()
    {
        DataSet ds = new DataSet();
        UserMemberService.UserMemberService oService = new UserMemberService.UserMemberService();
        //ds = oService.GetUserMemberByLoginEmail(Session["LoginName"].ToString());
        int id = Convert.ToInt32(Session["UserID"].ToString());
        ds = oService.GetUserMemberByID(id);

        DataTable dt = ds.Tables[0];

        if (dt.Rows.Count > 0 )
        {
            DataRow dr = dt.Rows[0];

           // HF_OldPwd.Value = dt.Rows[0].ItemArray["PASSWORD"].ToString();
            //Lbl_Name.Text = dt.Rows[0].ItemArray["LOGINEMAIL"].ToString();
            //Lbl_Name2.Text = dt.Rows[0].ItemArray["LOGINEMAIL"].ToString();
            //Lbl_No.Text = dt.Rows[0].ItemArray["DBLNO"].ToString();

            HF_OldPwd.Value = dr["PASSWORD"].ToString();
            Lbl_Name.Text = dr["LOGINEMAIL"].ToString();
            Lbl_Name2.Text = dr["LOGINEMAIL"].ToString();
            Lbl_No.Text = dr["DBLNO"].ToString();
            Txb_OldPwdOk.Text = dr["PASSWORD"].ToString();

            HF_Type.Value = dr["DBLTYPE"].ToString();

            if (HF_Type.Value.ToString() == "P")
            {
                div_PersionInfo.Visible = true;

                UserPersonService.UserPersonService upService = new UserPersonService.UserPersonService();

                ds = upService.FindPersonDetailByID(Session["UserID"].ToString());

                DataTable dtUp = ds.Tables[0];
                
                if (dtUp.Rows.Count>0)
                {
                    DataRow drUp = dtUp.Rows[0];

                    Txb_FullName.Text = drUp["FULLNAME"].ToString();
                    Txb_NickName.Text = drUp["NICKNAME"].ToString();
                    Txb_Phone.Text = drUp["PHONE"].ToString();
                    Txb_Mobile.Text = drUp["MOBILEPHONE"].ToString();
                    Txb_QQ.Text = drUp["QQ"].ToString();
                    Txb_MSN.Text = drUp["MSN"].ToString();
                    Txb_FAX.Text = drUp["FAX"].ToString();
                    Txb_KeyWord1.Text = drUp["KEYWORD1"].ToString();
                    Txb_KeyWord2.Text = drUp["KEYWORD2"].ToString();
                    Txb_KeyWord3.Text = drUp["KEYWORD3"].ToString();
                    Txb_WebSite.Text = drUp["WEBSITE"].ToString();
                    Txb_Blog.Text = drUp["BLOG"].ToString();
                    Txb_Weibo.Text = drUp["WEIBO"].ToString();
                    Txb_Address.Text = drUp["ADDRESS"].ToString();
                    Txb_Demo.Text = drUp["DESCRIPTION"].ToString();
                    Txb_PID.Text = drUp["SHENFENZHENG"].ToString();

                }


            }
            else if (HF_Type.Value.ToString() == "S")
            {
                div_ShopInfo.Visible = true;

                UserShopService.UserShopService usService = new UserShopService.UserShopService();

                ds = usService.FindShopDetailByID(id);

                DataTable dtUs = ds.Tables[0];

                if (dtUs.Rows.Count > 0)
                {
                    DataRow drUs = dtUs.Rows[0];

                    Txb_FullName.Text = drUs["FULLNAME"].ToString();
                    Txb_NickName.Text = drUs["NICKNAME"].ToString();
                    Txb_Phone.Text = drUs["PHONE"].ToString();
                    Txb_Mobile.Text = drUs["MOBILEPHONE"].ToString();
                    Txb_QQ.Text = drUs["QQ"].ToString();
                    Txb_MSN.Text = drUs["MSN"].ToString();
                    Txb_FAX.Text = drUs["FAX"].ToString();
                    Txb_KeyWord1.Text = drUs["KEYWORD1"].ToString();
                    Txb_KeyWord2.Text = drUs["KEYWORD2"].ToString();
                    Txb_KeyWord3.Text = drUs["KEYWORD3"].ToString();
                    Txb_WebSite.Text = drUs["WEBSITE"].ToString();
                    Txb_Blog.Text = drUs["BLOG"].ToString();
                    Txb_Weibo.Text = drUs["WEIBO"].ToString();
                    Txb_Address.Text = drUs["ADDRESS"].ToString();
                    Txb_Demo.Text = drUs["DESCRIPTION"].ToString();
                    Txb_ShopBoss.Text = drUs["SHOPBOSS"].ToString();

                }

            }
            else if (HF_Type.Value.ToString() == "C")
            {
                UserCompanyService.UserCompanyService ucService = new UserCompanyService.UserCompanyService();

                ds = ucService.FindCompanyDetailByID(id);

                DataTable dtUc = ds.Tables[0];

                if (dtUc.Rows.Count > 0)
                {
                    DataRow drUc = dtUc.Rows[0];

                    Txb_FullName.Text = drUc["FULLNAME"].ToString();
                    Txb_NickName.Text = drUc["NICKNAME"].ToString();
                    Txb_Phone.Text = drUc["PHONE"].ToString();
                    Txb_Mobile.Text = drUc["MOBILEPHONE"].ToString();
                    Txb_QQ.Text = drUc["QQ"].ToString();
                    Txb_MSN.Text = drUc["MSN"].ToString();
                    Txb_FAX.Text = drUc["FAX"].ToString();
                    Txb_KeyWord1.Text = drUc["KEYWORD1"].ToString();
                    Txb_KeyWord2.Text = drUc["KEYWORD2"].ToString();
                    Txb_KeyWord3.Text = drUc["KEYWORD3"].ToString();
                    Txb_WebSite.Text = drUc["WEBSITE"].ToString();
                    Txb_Blog.Text = drUc["BLOG"].ToString();
                    Txb_Weibo.Text = drUc["WEIBO"].ToString();
                    Txb_Address.Text = drUc["ADDRESS"].ToString();
                    Txb_Demo.Text = drUc["DESCRIPTION"].ToString();
                    

                }
            }
            else if (HF_Type.Value.ToString() == "O")
            {
                UserOrganizationService.UserOrganizationService uoService = new UserOrganizationService.UserOrganizationService();

                ds = uoService.FindOrganizationDetailByID(id);

                DataTable dtUo = ds.Tables[0];

                if (dtUo.Rows.Count > 0)
                {
                    DataRow drUo = dtUo.Rows[0];

                    Txb_FullName.Text = drUo["FULLNAME"].ToString();
                    Txb_NickName.Text = drUo["NICKNAME"].ToString();
                    Txb_Phone.Text = drUo["PHONE"].ToString();
                    Txb_Mobile.Text = drUo["MOBILEPHONE"].ToString();
                    Txb_QQ.Text = drUo["QQ"].ToString();
                    Txb_MSN.Text = drUo["MSN"].ToString();
                    Txb_FAX.Text = drUo["FAX"].ToString();
                    Txb_KeyWord1.Text = drUo["KEYWORD1"].ToString();
                    Txb_KeyWord2.Text = drUo["KEYWORD2"].ToString();
                    Txb_KeyWord3.Text = drUo["KEYWORD3"].ToString();
                    Txb_WebSite.Text = drUo["WEBSITE"].ToString();
                    Txb_Blog.Text = drUo["BLOG"].ToString();
                    Txb_Weibo.Text = drUo["WEIBO"].ToString();
                    Txb_Address.Text = drUo["ADDRESS"].ToString();
                    Txb_Demo.Text = drUo["DESCRIPTION"].ToString();
                   

                }
            }




        }


    }

    public void init_org()
    {
        DataSet ds = new DataSet();
        ToolService.ToolService oService = new ToolService.ToolService();

        ds = oService.GetAllProvince();
        DDL_Province.DataSource = ds;
        DDL_Province.DataTextField = "PROVINCENAME";
        DDL_Province.DataValueField = "CODE";
        DDL_Province.DataBind();


        ds = oService.GetAllCategory();
        DDL_Type.DataSource = ds;
        DDL_Type.DataTextField = "CATEGORYNAME";
        DDL_Type.DataValueField = "CATEGORYCODE";
        DDL_Type.DataBind();


        ds = oService.GetAllOrganizationType();
        DDL_Org.DataSource = ds;
        DDL_Org.DataTextField = "ORGNAME";
        DDL_Org.DataValueField = "ORGCODE";
        DDL_Org.DataBind();

        ds = oService.GetAllShopAttribute();
        DDL_ShopAttr.DataSource = ds;
        DDL_ShopAttr.DataTextField = "NAME";
        DDL_ShopAttr.DataValueField = "CODE";
        DDL_ShopAttr.DataBind();

    }
    protected void DDL_Province_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DDL_Province.SelectedItem.Text.ToString() != "请选择")
        {
            DataSet ds = new DataSet();
            ToolService.ToolService oService = new ToolService.ToolService();

            ds = oService.GetCityByProvinceCode(DDL_Province.SelectedValue.ToString());

            DDL_City.DataSource = ds;

            DDL_City.DataTextField = "CITYNAME";

            DDL_City.DataValueField = "CITYCODE";

            DDL_City.DataBind();
            //this.RegisterStartupScript("Msg", "<script>blendon('tabcontent2'); blendoff('tabcontent1');blendoff('tabcontent3');swichtabs('2');</script>");
        }

    }
    protected void DDL_City_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DDL_City.SelectedItem.Text.ToString() != "请选择")
        {
            DataSet ds = new DataSet();
            ToolService.ToolService oService = new ToolService.ToolService();

            ds = oService.GetDistrictByCityCode(DDL_City.SelectedValue.ToString());

            DDL_Distict.DataSource = ds;

            DDL_Distict.DataTextField = "DISTRICTNAME";

            DDL_Distict.DataValueField = "DISTRICTCODE";

            DDL_Distict.DataBind();
            //this.RegisterStartupScript("Msg", "<script>blendon('tabcontent2'); blendoff('tabcontent1');blendoff('tabcontent3');swichtabs('2');</script>");
        }
    }
    protected void DDL_Type_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DDL_Type.SelectedItem.Text.ToString() != "请选择")
        {
            DataSet ds = new DataSet();
            ToolService.ToolService oService = new ToolService.ToolService();

            ds = oService.GetClassificationByCategory(DDL_Type.SelectedValue.ToString());

            DDL_SType.DataSource = ds;

            DDL_SType.DataTextField = "CLASSIFICATIONNAME";

            DDL_SType.DataValueField = "CLASSIFICATIONFULLCODE";

            DDL_SType.DataBind();
            //this.RegisterStartupScript("Msg", "<script>blendon('tabcontent2'); blendoff('tabcontent1');blendoff('tabcontent3');swichtabs('2');</script>");
        }
    }




    protected void DDL_Distict_SelectedIndexChanged(object sender, EventArgs e)
    {
        Txb_Location.Text = DDL_Distict.SelectedItem.Text.ToString();
    }
    protected void DDL_SType_SelectedIndexChanged(object sender, EventArgs e)
    {
        Txb_Type.Text = DDL_SType.SelectedItem.Text.ToString();

    }
    protected void DDL_Org_SelectedIndexChanged(object sender, EventArgs e)
    {
        Txb_Org.Text = DDL_Org.SelectedItem.Text.ToString();
    }
    protected void DDL_ShopAttr_SelectedIndexChanged(object sender, EventArgs e)
    {
        Txb_ShopAttr.Text = DDL_ShopAttr.SelectedItem.Text.ToString();
    }
}
